package com.bookstore.spring.filter;

import org.apache.ibatis.session.SqlSession;
import com.bookstore.spring.util.MybatisSessionFactory;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * Created by Admin on 2016/9/9.
 */
@WebFilter("/index.jsp")
public class LoginFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request= (HttpServletRequest) req;
        HttpServletResponse response= (HttpServletResponse) resp;
        String servletPath=request.getServletPath();
        SqlSession sqlSession=null;
        try{
            sqlSession= MybatisSessionFactory.getSession();
            if(servletPath.equals("/index.jsp")) {
                filterChain.doFilter(request, response);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    @Override
    public void destroy() {

    }
}
